package com.java.jvm.memory;
/**
 * 标量替换JVM参数：-XX:+EliminateAllocations
 * -Xmx128m -Xms128m -XX:+DoEscapeAnalysis -XX:-EliminateAllocations XX:+PrintGC
 */
public class ObjectScalarReplaceTests {
    public static void main(String args[]) throws InterruptedException {
        long start = System.currentTimeMillis();
        for (int i = 0; i < 10000000; i++) {
            alloc();
        }
        long end = System.currentTimeMillis();
        System.out.println("花费的时间为： " + (end - start) + " ms");
    }
    //static Point point;
    private static void alloc() {
        //未逃逸的小对象
        Point point = new Point(1,2);
        //如上对象标量替换为
        //int x=1;//局部变量是在栈上分配的
        //int y=2;
    }
    static class Point {
        private int x;
        private int y;
        public Point(int x,int y){
            this.x=x;
            this.y=y;
        }
    }
}
